package com.computec.service.client;


import java.util.Iterator;

import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;

public class Scenario1Client {

    public static void main(String[] args) throws Exception {
        ServiceClient client = new ServiceClient();
        // create option object
        Options opts = new Options();
        //setting target EPR
        opts.setTo(new EndpointReference("http://127.0.0.1:48080/axis2/services/CommandService"));
        //Setting action ,and which can be found from the wsdl of the service
        opts.setAction("urn:runCommand");
        client.setOptions(opts);
        Boolean b=new Boolean(false);
        OMElement res=null;
		try {
			res = client.sendReceive(createPayLoad());
		} catch (Exception e) {

		}        
		if(res!=null){
	        Iterator it=res.getChildElements();
	        for(;it.hasNext();){
	        	OMElement o=(OMElement)it.next();        	
	        	b=new Boolean(o.getText());
	        }
	        System.out.println(res);
		}
        System.out.println("Ejecuto:"+b);
        

    }

    public static OMElement createPayLoad() {
        OMFactory fac = OMAbstractFactory.getOMFactory();
        OMNamespace omNs = fac.createOMNamespace("http://command.service.computec.com", "ns1");
        OMElement method = fac.createOMElement("runCommand", omNs);
        OMElement value = fac.createOMElement("value", omNs);        
        value.setText("cmd /c calc");
        method.addChild(value);
        return method;
    }

}
